<?php
/**
 * @Notes:【】
 * @Date: 2022-06-05 15:23
 */

namespace Form;

use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\PostApi;
use Yj\ColumnBuilder\Column;
use Yj\Form\Elm;

/**
 * @ApiController(prefix="form/product")
 */
class Product extends \Yj\Form\BaseForm
{

    protected $yjCode = 'product/product';

    public function getColumn()
    {
        $colum = Column::create();
        $colum->setRules([
            Column::txt()->setLabel('商品ID')->setProp('id'),
            Column::image()->setLabel('商品图')->setProp('image'),
            Column::txt()->setLabel('商品名称')->setProp('store_name')->setWidth('300'),
            Column::txt()->setLabel('商品类型')->setProp('cate_id'),
            Column::txt()->setLabel('商品售价')->setProp('price'),
            Column::txt()->setLabel('商品销量')->setProp('sales'),
            Column::txt()->setLabel('商品库存')->setProp('stock'),
            Column::txt()->setLabel('排序')->setProp('sort'),
            Column::switch()->setUrl($this->createRoute('set-show'))->setLabel('是否显示')->setProp('is_show'),
        ]);
        return $colum->toArray();
    }

    protected function getRoute($types = null)
    {
        if (is_null($types)) {
            return $this->routes;
        }
        return $this->routes[$types];
    }

    /**
     * @PostApi(path="config",description="配置")
     */
    public function config()
    {
        $routes = $this->getRoute();
        $column = $this->getColumn();
        _SUCCESS(compact('routes', 'column'));
    }

    /**
     * @PostApi(path="update",description="添加")
     */
    public function update()
    {
        $form = Elm::createForm($this->getRoute('add'));
        $form->setRule([
            Elm::input('title', '名称')->required(),

        ]);
        $lists = $form->setTitle('添加题库')->formData([]);
        _SUCCESS(formToData($lists));
    }
}